// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env:'mupp-5gs2863z7cf6873f'
})

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const db=cloud.database()
  const comment = db.collection('comment')
  let openid=wxContext.OPENID
      var date = new Date(); //创建时间对象
      var year = date.getFullYear(); //获取年      
      var month = date.getMonth() + 1; //获取月
      var day = date.getDate(); //获取日
      var time = year+"年"+month+"月"+day+"日"
  let fileidArr = event.fileidArr 
  let Msg = await comment.add({
    data:{
      cid:fileidArr[0],
      openid:event.openid,
      nickName:event.nickName,
      avatarUrl:event.avatarUrl,
      imgUrl:fileidArr,
      text:event.textareaTxt,
      time:time,
      dz:[]
    }
  })

  return {
    Msg,
    
  }
}